Regression test for lockfile format
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 22 Aug 2016 23:59:31 +0000 (02:59 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 23 Aug 2016 12:44:07 +0000 (15:44 +0300)
tests/cargotest/support/mod.rs
tests/lockfile-compat.rs

index 13397811f03b0f8bf28ec4d79117e6dbe8f7d69d..8ade994c9c803beee2410f4698a5c0530fa3adef 100644 (file)
@@ -412,7 +412,7 @@ impl Execs {
     }
 }
 
-fn lines_match(expected: &str, mut actual: &str) -> bool {
+pub fn lines_match(expected: &str, mut actual: &str) -> bool {
     for (i, part) in expected.split("[..]").enumerate() {
         match actual.find(part) {
             Some(j) => {
index 4ebba15ea18b5137ca80950e87248b6bf84f77dd..5fa34452be7f3cb138eb61f41b5281c9ef4fefed 100644 (file)
@@ -7,7 +7,7 @@ use std::io::prelude::*;
 
 use cargotest::support::git;
 use cargotest::support::registry::Package;
-use cargotest::support::{execs, project};
+use cargotest::support::{execs, project, lines_match};
 use hamcrest::assert_that;
 
 #[test]
@@ -277,6 +277,52 @@ unable to verify that `foo v0.1.0 ([..])` is the same as when the lockfile was g
 "));
 }
 
+#[test]
+fn current_lockfile_format() {
+    Package::new("foo", "0.1.0").publish();
+
+    let p = project("bar")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = "0.1.0"
+        "#)
+        .file("src/lib.rs", "");
+    p.build();
+
+    assert_that(p.cargo("build"), execs().with_status(0));
+
+    let mut actual = String::new();
+    File::open(p.root().join("Cargo.lock")).unwrap()
+        .read_to_string(&mut actual).unwrap();
+
+    let expected = "\
+[root]
+name = \"bar\"
+version = \"0.0.1\"
+dependencies = [
+ \"foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",
+]
+
+[[package]]
+name = \"foo\"
+version = \"0.1.0\"
+source = \"registry+https://github.com/rust-lang/crates.io-index\"
+
+[metadata]
+\"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"[..]\"";
+
+    for (l, r) in expected.lines().zip(actual.lines()) {
+        assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r);
+    }
+
+    assert_eq!(actual.lines().count(), expected.lines().count());
+}
+
 #[test]
 fn lockfile_without_root() {
     Package::new("foo", "0.1.0").publish();
@@ -309,8 +355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
     File::create(p.root().join("Cargo.lock")).unwrap()
         .write_all(lockfile.as_bytes()).unwrap();
 
-    assert_that(p.cargo("build"),
-                execs().with_status(0));
+    assert_that(p.cargo("build"), execs().with_status(0));
 
     let mut lock = String::new();
     File::open(p.root().join("Cargo.lock")).unwrap()